﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DefCore.Core
{
    public class GlobalTickEventArgs : EventArgs
    {
        public GlobalTickEventArgs()
	    {

	    }
    }

    public sealed class TickControl
    {
        private readonly double TickTime = 1.00d;

        private static TickControl _Instance;
        public static TickControl Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new TickControl();

                return _Instance;
            }
        }
        
        //Fields
        private TimeSpan _TickCounter;
        public event EventHandler<GlobalTickEventArgs> OnTick = delegate { };

        //ctor 
        public TickControl()
        {
            _TickCounter = TimeSpan.FromSeconds(0);
        }

        //Methods
        public void Update(GameTime time)
        {
            _TickCounter += time.ElapsedGameTime;

            if (_TickCounter >= TimeSpan.FromSeconds(TickTime))
            {
                OnTick(this, new GlobalTickEventArgs());
                _TickCounter -= TimeSpan.FromSeconds(TickTime);
            }
        }
    }
}
